<%--
 *  File:    DataCleanMannual.jsp
 *  @Author: Jamesli
 *  Date:    2010/07/25
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DataCleanMannual"); 

  //init param
  String strModuleName = "CM";
  String privilegeCode = "E0212";
  String strTableName = "v_prodcollateedit";
  String contextPath = request.getContextPath();
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DataCleanMannual</title>
<PageFlow:CheckPageFlow pageName="p_datacleanmanual"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%
	Vector errorcode = (Vector)session.getAttribute("errorcode");
	if(errorcode == null) errorcode = new Vector();
	String orgoptionvalue = (String)pageContext.getAttribute("orgoption");
	if(orgoptionvalue == null)orgoptionvalue = "1";
%>
<%@ include file="/inc/AlertError.inc" %>
<script>
function page_checkall(){
	var numrows = cform.numrows.value;
	var allcheck = cform.checkall;
	var allprod = document.getElementsByName("tempids");
	for(var i = 0 ; i < allprod.length ; i++){
		allprod[i].checked = allcheck.checked;
	}
}

function page_allintocollate(){
	var numrows = cform.numrows.value;
	var allcheck = cform.allintocollate;
	for(var i = 0 ; i < numrows;i++){
		eval("cform.needsync" + i).checked = allcheck.checked;
		if(!allcheck.checked) eval("cform.isdefault" + i).checked = allcheck.checked;
	}
}

function page_allisdefault(){
	var numrows = cform.numrows.value;
	var allcheck = cform.allisdefault;
	for(var i = 0 ; i < numrows;i++){
		if(eval("cform.needsync" + i).checked) eval("cform.isdefault" + i).checked = allcheck.checked;
	}
}

function page_uncheckall(element){
	if(!element.checked)cform.checkall.checked = false;
}

function page_uncheckallintocollate(element){
	if(!element.checked){
		cform.allintocollate.checked = false;
		var isdefaultElement = eval("cform." + element.name.replace(/needsync/,"isdefault"));
		isdefaultElement.checked = false;
	}
}

function page_uncheckallisdefault(element){
	if(!element.checked)cform.allisdefault.checked = false;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DataCleanManual.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}


var popwindow;

function page_selectproduct(returnvalue){
	if(popwindow!=null) popwindow.close();
	popwindow = window.open("<%=contextPath%>/phap/phap.datp/masterdata/kdm/ProductSelect.jsp?<%= OvalTools.randomURL() %>&returnvalue=" + returnvalue+"&status=41", "newwindow", "height=400, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}

function page_setproduct(id,umcode,prodcode,prodname,idx){
	eval('document.cform.prodid' + idx).value = id;
	eval('document.cform.prodcode' + idx).value = prodcode;
	eval('document.cform.prdn' + idx).value = prodname;
}

function page_errorfile(tempid)
{
	var processtype = cform.processtype.value;
  	if(popwindow!=null) popwindow.close();
  popwindow = window.open('<%=contextPath %>/phap/phap.datp/masterdata/cm/dataclean/DataCleanManualErrorFile.jsp?<%= OvalTools.randomURL() %>&tempid=' + tempid + '&processtype=' + processtype,'newwindow', 'height=500, width=1100,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=yes, location=no, status=no');
}

function page_checkproduct(idx)
{
   eval('document.cform.prodid' + idx).value = "";
   eval('document.cform.prdn' + idx).value="";

   if(isEmpty(eval('document.cform.prodcode' + idx).value))
   {
	   eval('document.cform.prodcode' + idx).value = "";
        return;
   }

    var  datahandler = new  DataHandler() ;
    datahandler.add_params("searchname" , "prodcode") ;
    datahandler.add_params("searchvalue" , eval('document.cform.prodcode' + idx).value) ;
    datahandler.getResultFromHashMap("totalsummary" ,"prodcode" ,"document.cform.prodcode" + idx);
    datahandler.getResultFromHashMap("totalsummary" ,"prodid" ,"document.cform.prodid" + idx);
    datahandler.getResultFromHashMap("totalsummary" ,"prodname" ,"document.cform.prdn" + idx);
    datahandler.add_job("j_productsummary");
    datahandler.runDataHandler ();
}

function page_multicollatepop(){
	var allprod = document.getElementsByName("tempids");
	var checkflag = false;
	for(var i = 0 ; i < allprod.length; i++){
		if(allprod[i].checked){
			checkflag = true;
			break;
		} 
	}
	if(!checkflag){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}
	
  	if(popwindow!=null) popwindow.close();
  	popwindow = window.open('<%=contextPath %>/phap/phap.datp/masterdata/cm/dataclean/ProductSelect4MultiCollate.jsp?<%= OvalTools.randomURL() %>','newwindow', 'height=400, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=yes, location=no, status=no');
}

function page_setmulticollate(id){
	var allprod = document.getElementsByName("tempids");
	var checkflag = false;
	for(var i = 0 ; i < allprod.length; i++){
		if(allprod[i].checked){
			checkflag = true;
			break;
		} 
	}
	if(!checkflag){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}
	cform.prodid.value = id;
	formatCheckBox(document.cform);
	document.cform.target = "_self";
	document.cform.actionname.value = "multicollatesave";
	isRunning = true;
	document.cform.submit();
}

function page_save(){
	formatCheckBox(document.cform);
	document.cform.target = "_self";
	document.cform.actionname.value = "save";
	isRunning = true;
	document.cform.submit();
}

function page_onload(){
	<%if(errorcode.size() != 0){%>
		self.location.href="<%=contextPath %>/Blank.jsp";
	<%}%>
}
</script>
</head>
<body onload="page_onload()">
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_self">
	<input type="hidden" name="pagename" value="p_datacleanmanual">
	<input type="hidden" name="actionname">
	<input type="hidden" name="prodid">
	<custom:hidden property="processtype"/>
	<custom:hidden property="languagecode" scope="session"/>
	<custom:hidden property="datafrequency"></custom:hidden>
   <tr>
    <td>
          <table width="100%" border="0" cellspacing="0">
          	<tr>
	          <td class="summary_top" colspan="2" ></td>
	        </tr>
            <%@ include file="/inc/SummarySearch.inc" %>
          </table>
        </td>
  </tr>
  <tr> 
    <td class="td_center"> 
    <div style="width:100%;height=400;padding-left:1px;padding-right:1px;overflow=auto;">
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
         	<td width="2%" class="title_center"><custom:checkbox property="checkall" onclick="page_checkall()" styleClass="checkbox"/></td>
         	<td width="8%" class="title_center"><%= label.getLabelName("L_DealerCode")%></td>
            <td width="*%" class="title_center"><%= label.getLabelName("L_DealerName") %></td>
            <%if(orgoptionvalue.equals("2")){ %>
            <td width="13%" class="title_center"><%= label.getLabelName("L_ProdCode") %></td>
            <td width="15%" class="title_center"><%= label.getLabelName("L_ProdName")%></td>
            <%}else{ %>
            <td width="15%" class="title_center"><%= label.getLabelName("L_ProdName")%></td>
            <td width="13%" class="title_center"><%= label.getLabelName("L_Spec1") %></td>
            <%} %>
            <td width="20%" class="title_center"><%= label.getLabelName("L_MapToProduct") %></td>
            <td width="7%" class="title_center">&nbsp;</td>
            <td width="9%" class="title_center">
            	<custom:checkbox property="allintocollate" styleClass="checkbox" onclick="page_allintocollate()" value="Y"/>
            	<%= label.getLabelName("L_IntoCollateOrNot") %>
            </td>
            <td width="9%" class="title_center">
            	<custom:checkbox property="allisdefault" styleClass="checkbox" onclick="page_allisdefault()"/>
            	<%= label.getLabelName("L_IsDefaultCollate") %>
            </td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
             Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
             if(totalsummary == null) totalsummary = new Vector();
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
           
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
           	<td class="td_center"><custom:checkbox property="prodcollatetmpid" name="summary" changedName="tempids" styleClass="checkbox" onclick="page_uncheckall(this)"/></td>
           	<custom:hidden property="prodcollatetmpid" name="summary" colIndex="<%=new Integer(j) %>"/>
           	<td>&nbsp;<custom:write property="dtcode" name="summary"/></td>
            <td>&nbsp;<custom:write property="dtname" name="summary"/></td>
            <%if(orgoptionvalue.equals("2")){ %>
            <td>&nbsp;<custom:write property="prodcode" name="summary"/></td>
            <td>&nbsp;<custom:write property="prodname" name="summary"/></td>
            <%}else{ %>
            <td>&nbsp;<custom:write property="prodname" name="summary"/></td>
            <td>&nbsp;<custom:write property="spec" name="summary"/></td>
            <%} %>
            <td>
            	<custom:hidden property="prodid" colIndex="<%=new Integer(j) %>"/>
            	<input type="text" name="prodcode<%=j %>" size="15" onchange="page_checkproduct('<%=j %>')">
                <a onclick="page_selectproduct(<%=j %>)"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                <custom:text property="prdn" style="border:0" readonly="true" size="20" colIndex="<%=new Integer(j) %>"/>
            </td>
            <td class="td_center"><a onclick="page_errorfile(<custom:write property="prodcollatetmpid" name="summary"/>)"><%= label.getLabelName("L_ErrorFile") %></a></td>
            <td class="td_center"><custom:checkbox property="needsync" name="summary" checkFlag="Y/N" styleClass="checkbox" onclick="page_uncheckallintocollate(this)" colIndex="<%=new Integer(j) %>"/></td>
            <td class="td_center"><custom:checkbox property="isdefault" name="summary" checkFlag="Y/N" styleClass="checkbox" onclick="page_uncheckallisdefault(this)" colIndex="<%=new Integer(j) %>"/></td>
          </tr>
          <%
          j++;     
          %>
          </logic:iterate>
          <input type="hidden" name="numrows" value="<%=j + "" %>">
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      </div>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
          	<%if(j != 0){ %>
            <a onclick="page_save()"><custom:button type="1" label="L_Save" imgsrc="edit.gif" border="0" style="width:60"/></a>
            <a onclick="page_multicollatepop()"><custom:button type="1" label="L_MultiCollate" imgsrc="edit.gif" border="0" style="width:80"/></a>
            <%}else{ %>&nbsp;<%} %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
</html>